<template>
  <div class="article-item">
    <div class="details">
      <div class="user-info">
        <Avatar :userId="data.userId" :width="30" style="margin-right: 5px;" />
        <router-link :to="'/user/' + data.userId" class="link-info"><div>{{ data.nickName }}</div></router-link>
        <el-divider direction="vertical" />

        <div>{{ data.userIpAddress }}</div>
        <el-divider direction="vertical" />

        <div>{{ data.postTime }}</div>
        <el-divider direction="vertical" />
        <router-link :to="`/forum/${data.pboardId}`" class="link-info">{{ data.pboardName }}</router-link>

        <template v-if="data.boardName">
          <el-divider direction="vertical" />
          <router-link :to="`/forum/${data.pboardId}/${data.boardId}`" class="link-info">{{ data.boardName }}</router-link>
        </template>
      </div>

      <div class="article-content">
        <router-link :to="`/post/${data.articleId}`" class="title">
          <span class="top"  v-if="data.topType == 1">置顶</span>
          <span>{{ data.title }}</span>
        </router-link>
        <div class="summary">{{ data.summary }}</div>
      </div>
      <div class="stats">
        <span class="iconfont icon-eye-solid">
          {{ data.readCount == 0 ? "阅读" : data.readCount }}
        </span>
        <span class="iconfont icon-good">
          {{ data.goodCount == 0 ? "点赞" : data.goodCount }}
        </span>
        <span class="iconfont icon-comment">
          {{ data.commentCount == 0 ? "评论" : data.commentCount }}
        </span>
      </div>
    </div>
    <div v-if="data.cover" class="cover-container">
      <router-link :to="`/post/${data.articleId}`">
        <Cover v-if="data.cover" :cover="data.cover" :width="120" />
      </router-link>
    </div>
  </div>
</template>
  
  <script setup>
import Avatar from '@/components/Avatar.vue';
import Cover from '@/components/Cover.vue';

  const props = defineProps({
    data: {
      type: Object,
      required: true,
    },
  });
  </script>
 

 <style lang="scss">
.article-item {
  display: flex;
  gap: 10px; /* 格子之间的间距 */
  border-bottom: 1px solid #ccc;
  padding: 10px 0;
  align-items: center;

  .details {
    flex-grow: 1; /* 让details占据剩余的空间 */
    display: grid;
    grid-template-rows: auto auto auto; /* 分为三行 */
    gap: 0px; /* 行之间的间距 */
    padding-left: 10px;
    .user-info {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #9a9a9a;
      margin-block: 5px;

      .name-location {
        display: flex;
        align-items: center;
        gap: 10px; /* 昵称和地址之间的间距 */

        span {
          margin-bottom: 5px;
        }
      }
      .link-info {
        color: #656565;
        text-decoration: none;
      }
      .link-info:hover {
        color: var(--link);
      }
    }

    .article-content {
      .title {
        text-decoration: none;
        font-weight: bold;
        font-size: 16px; /* 设置标题字体大小 */
        color: #333; /* 设置标题字体颜色 */
        display: inline-block;
        margin: 6px 0px; /* 添加底部间距 */
        .top{
          font-weight: normal;
          font-size: 12px;
          border-radius: 5px;
          border: 1px solid var(--pink);
          color:  var(--pink);
          padding: 0px 5px;
          margin-right: 10px;
        }
      }
      .summary {
        font-size: 14px; /* 设置简介字体大小 */
        color: #606060;
        height: 38px;
        margin-bottom: 6px; /* 添加底部间距 */
      }
    }

    .stats {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 10px; /* 点赞数、阅读数和评论数之间的间距 */
      font-size: 10px; /* 减小字体大小 */
      color: #999; /* 修改字体颜色 */

      .iconfont {
        color: #878585;
        margin-right: 15px;
        font-size: 14px;
      }
      .iconfont:before {
        padding-right: 3px;
      }
    }
  }

  .cover-container {
    width: 120px;
    min-width: 120px; /* 确保即使没有Cover，也会占据120px的空间 */
    flex-shrink: 0; /* 防止收缩 */
    margin-right: 20px;
  }
}
</style>